package minisoft.application.loterryservice;


import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


public class TodayAdapter extends BaseAdapter {

	private Context mContext;
	private List<Today> mItems;
	
	public TodayAdapter(Context c, List<Today> items) {
		mContext = c;
		mItems = items;
	}
	
	@Override
	public int getCount() {
		return mItems.size();
	}

	@Override
	public Object getItem(int position) {
		return mItems.get(position);
	}
	
	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
		View aView = inflater.inflate( R.layout.today_row, null );
		
		
		TextView province = (TextView)aView.findViewById(R.id.province);
		TextView timeSpan = (TextView)aView.findViewById(R.id.timeSpan);
			
		province.setText(String.valueOf(mItems.get(position).getProvinceName()));
		timeSpan.setText(mItems.get(position).getTimeSpan());
		
		return aView;
	}
	
	public void add(Today aToday)
	{
		mItems.add(aToday);
	}
	public void update(Today aToday, int pos)
	{
		mItems.set(pos, aToday);
	}	
	
	public void clear()
	{
		mItems.clear();
	}
}
